 <link rel="stylesheet" type="text/css" href="css/backend/module.css" />
<style type="text/css">  
    .c-label{  
        display:inline-block;  
        width:100px; 
        font-weight:bold;  
    }  
</style> 

<table id="authoritypanel" >  
</table>    
<script>  
    var cardview = $.extend({}, $.fn.datagrid.defaults.view, {  
        renderRow: function(target, fields, frozen, rowIndex, rowData){  
            var arr = [];  
            arr.push('<td colspan=' + fields.length + ' style="padding:10px 5px;border:0;">');  
            if (!frozen){  
                var brr = rowData.ID.split('-');  
                var img = 'shirt' + brr[1] + '.gif';  
                arr.push('<img src="images/backend/role_grid.png" style="float:left">');  
                arr.push('<div style="float:left;margin-left:20px;">');  
                for(var i=0; i<fields.length; i++){  
                    var copts = $(target).datagrid('getColumnOption', fields[i]);  
                    arr.push('<p><span class="c-label">' + copts.title + ':</span> ' + rowData[fields[i]] + '</p>');  
                }  
                arr.push('</div>');  
            }  
            arr.push('</td>');  
            return arr.join('');  
        }
    });  
    function showWin(title,name,id) {
        $('#rolename').val(name); 
        $('#win').dialog({
            title : title,
            height : 300,
            width : 400,
            modal : true,
            buttons : [{
                text:'保存',
                iconCls:'icon-save',
                handler:function(){
                    var selecteds = [];
                    $.each ($('#basetree').tree('getChecked'),function(i,s){
                        selecteds.push(s.id);
                    })
                    var url = 'backend.php?r=authority/create/modules/' + selecteds.toString() + '/id/' + id;
                    submitForm('authority_form',url,'win','authoritypanel');
                }
            },{
                text:'取消',
                iconCls:'icon-cancel',
                handler:function(){
                    $('#win').dialog('close');
                }
            }]
        });
        $('#basetree').tree({  
            checkbox : true,  
            animate : true,  
            url: 'backend.php?r=authority/listbyid/id/' + id,  
            cascadeCheck : true,  
            onlyLeafCheck : true
        }); 
    }
    $(function(){  
        $('#authoritypanel').datagrid({  
            title : '管理员权限管理',
            fit : true,
            view : cardview,
            showHeader:false,
            singleSelect : true,
            fitColumns : true,
            url : "backend.php?r=authority/list",
            pagination : "true",
            columns : [[                 
                    { field: 'Name', title: '角色名称',width:100,align: 'center'},
                    { field: 'AuthorityList', title: '权限明细',width:200,  align: 'center' }
                ]],
             toolbar : [{
                id:'btnreload',
                text:'刷新',
                iconCls:'icon-reload',
                handler:function(){
                    $('#authoritypanel').datagrid('reload');
                }
            }, '-', {
                id:'btnadd',
                text:'添加',
                iconCls:'icon-add',
                handler:function(){
                    showWin('添加角色','',0);


                }
            },'-', {
                id:'btnedit',
                text:'编辑',
                iconCls:'icon-edit',
                handler:function(){
                    alert('edit');return;
                    $('#authoritypanel').datagrid('reload');
                }
            }, '-', {
                id:'btnremove',
                text:'删除',
                iconCls:'icon-remove',
                handler:function(){
                    var selected = $('#authoritypanel').datagrid('getSelected');
                    if (selected){
                        Tool.delRequest({id:selected.ID}, 'backend.php?r=authority/delete',function(result){
                            if (result.success)
                            {
                                $('#authoritypanel').datagrid('reload');
                                $.messager.alert( '系统提示',result.msg, 'info');
                            }
                        });
                    }
                    else
                    {
                        $.messager.alert( '系统提示','请先选择数据', 'warning');	 
                    } 
                }
            }],
            onDblClickRow : function(index,row) {
                showWin('编辑角色(' +row.Name + ')',row.Name,row.ID);
            }
        });  
    });  
</script>  
<div id="win" style='margin-left:80px;'> 
        <form id="authority_form" method="post" novalidate>
            <div style='margin:10px 10px 0px 10px;'>
                <label for="Name">角色名称:</label>
                <input class="easyui-validatebox" type="text" name="Name" id='rolename' data-options="required:true"></input>
            </div>
            <div style='margin:10px 10px 0px 10px;'>
                <label for="Module">权限列表:</label>
                <ul id="basetree" style='margin:10px 0 0 10px;'></ul>
            </div>
        </form>
<!--    <div id="win" class="easyui-dialog" title="编辑" data-options="modal:true,closed:true" style="width:500px;height:200px;padding:10px;"> --> 
</div>  